<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入-100的整数" id="t1" >
<input type="button" value="猜一猜" onclick="f1()">
<div>结果:<span></span></div>
<script>
     //得到0-100的随机整数
     let x=parseInt(Math.random()*101);
     let i = 0;
     function f1(){
         ++i;
      let t1 = document.querySelector("#t1");
      let d = document.querySelector("span");
      if(isNaN(t1.value)){
          d.innerText = "输入有误";
          return;
      }
          if(x==t1.value){
              d.innerText = "猜对了猜了"+i;
              i=0;
              x = parseInt(Math.random()*101);
          }else if(t1.value>x){
              d.innerText = "猜大了";
          }
          else {
              d.innerText = "猜小了";
          }

     }
</script>
</body>
</html>